const express = require('express');
const logger = require('morgan');

const ej = require( 'express-jwt' );

const customerRouter = require( './routes/customer' );
const studentRouter = require( './routes/student' );

const port = 9090 ;
const app = express();

app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));

const jwtMiddleware = ej( { 
    secret: 'kaifamiao' , 
    credentialsRequired: false ,
    algorithms: ['HS256']
} ).unless({
    path:['/customer/sign/in']
});
// 使用 express-jwt 提供的中间件支持解析Token
app.use( jwtMiddleware );

app.use( customerRouter );
app.use( studentRouter );

app.listen( port );